<template>
	<view style="height: 100%;position: fixed;width: 100%;"  v-if="currentId!=null">
		<view style="background-color: #FFFFFF;padding: 20rpx 40rpx;" @click="toSearch">
			<u-search placeholder="请输入内容" @focus="toSearch"></u-search>
		</view>
		<view class="content" v-show="cateList">
			<scroll-view scroll-y class="left-aside">
				<view v-for="(item,index) in cateList" :key="index" class="f-item b-b"
					:class="{active: index === currentId}" @click="tabtap(item,index)">
					{{item.name}}
				</view>
			</scroll-view>
			<scroll-view scroll-with-animation scroll-y class="right-aside" >
				<view v-for="(titem,index) in cateList[currentId].children" :key="index" >
					<view class="title" >
						<text>{{titem.name}}</text>
					</view>
					<view class="t-list">
						<view class="t-item"  v-for="lists in titem.children" :key="lists.id" @click="tonav(lists.id)">
							<image :src="lists.icon"></image>
							<text>{{lists.name}}</text>
						</view>
					</view>
				</view>

			</scroll-view>
		</view>
	</view>

</template>

<script>
	export default {
		data() {
			return {
				indicColor: "#000",
				cateList: [], //一级目录
				currentId: null,
				tlist: [], //二级目录
				list: [],
				adList: [], //广告
				brandList: [] ,//品牌,
			}
		},
		onLoad() {
			this.getcataList()
		},
		onShow() {
			// 获取购物车数量
			if(uni.getStorageSync('authStatus') == true){
				this.$api.request.getShopCart({}, res => {
					// this.cartList=res.data
					if(res.data.length > 0){
						uni.setTabBarBadge({
							index: 2,
							text: res.data.length.toString()
						})
					}
					else{
						uni.removeTabBarBadge({
							index: 2
						})
					}
				})
			}
			
		},
		methods: {
			tonav(id){
				uni.navigateTo({
					url:"/pages/sys/common/search?f=2&catalogId="+id
				})
			},
			getcataList() {
				this.$api.request.catalogList({}, res => {
					console.log(res);
					this.currentId=0
					this.cateList = res.data
					
					
					// res.data.forEach(item=>{
					// 	this.$api.request.twoCatalogList({
					// 		id:item.id
					// 	},date=>{
					// 		item.list = date.data
					// 		item.list.forEach(list=>{
					// 			this.$api.request.threeCatalogList({
					// 				id:list.id
					// 			},abc=>{
					// 				list.list= abc.data
					// 				this.cateList = res.data
					// 				console.log(this.cateList);
					// 				setTimeout(res=>{
					// 					this.currentId=0
					// 				},100)
					// 			})
					// 		})
					// 		// console.log("res",res);
					// 	})
					// })
				})
			},
			toSearch() {
				uni.navigateTo({
					url: "/pages/sys/common/search"
				})
			},
			inquiryProductCate() {
				this.$api.request.productCate({}, res => {
					if (res.body.status.statusCode === '0') {
						this.cateList = res.body.data.cates;
						//默认选中
						if (this.cateList.length > 0) {
							this.tabtap(this.cateList[0]);
						}
					} else {
						console.log(res.body.status.errorDesc);
					}
				});
			},
			//一级分类点击
			tabtap(item, index) {
				console.log("index",item);
				if(item.list.length==0){
					this.tonav(item.id)
				}else{
					this.currentId = index;
				}
			},
		}
	}
</script>

<style lang='scss'>
	page,
	.content {
		height: 100%;
		background-color: #f8f8f8;
	}

	.content {
		display: flex;
	}

	.left-aside {
		flex-shrink: 0;
		width: 200upx;
		height: 100%;
		background-color: #fff;
	}

	.f-item {
		display: flex;
		align-items: center;
		justify-content: center;
		width: 100%;
		height: 100upx;
		font-size: 28upx;
		color: $font-color-base;
		position: relative;

		&.active {
			/* color: $base-color; */
			color: #7EAFA5;
			background: #f8f8f8;

			&:before {
				content: '';
				position: absolute;
				left: 0;
				top: 50%;
				transform: translateY(-50%);
				height: 36upx;
				width: 8upx;
				background-color: #7EAFA5;
				border-radius: 0 4px 4px 0;
				opacity: .8;
			}
		}
	}

	.right-aside {
		flex: 1;
		overflow: hidden;
		padding-left: 20upx;
	}

	.ad {
		width: 100%;
		height: 210upx;
		padding: 10upx 0;
		background: #fff;

		image {
			width: 100%;
			height: 100%;
		}
	}

	.title {
		background: #fff;
		font-size: 26upx;
		color: $font-color-dark;
		font-weight: bold;
		margin-top: 10px;
		padding: 10px 0 0 10px;
	}

	.t-list {
		display: flex;
		flex-wrap: wrap;
		width: 100%;
		background: #fff;
		padding-top: 12upx;

		&:after {
			content: '';
			flex: 99;
			height: 0;
		}
	}

	.t-item {
		flex-shrink: 0;
		display: flex;
		justify-content: center;
		align-items: center;
		flex-direction: column;
		width: 176upx;
		font-size: 26upx;
		color: #666;
		padding-bottom: 20upx;

		image {
			width: 140upx;
			height: 140upx;
			padding: 20upx;
		}
	}
</style>
